package stream;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: YKH
 * Date: 2023-03-27
 * Time: 9:32
 */
public class StreamTest {
    public static void main(String[] args) {

        Person person1 = new Person(1,"张三","男");
        Person person2 = new Person(2,"李四","男");
        Person person3 = new Person(3,"王五","男");
        Person person4 = new Person(4,"张三","男");
        //使用Stream,of静态方法动态创建 集合
        List<Person> personList = Stream.of(person1, person2, person3, person4).collect(Collectors.toList());
        //使用 filter方法过滤出姓名为张三的人加入新的集合
        List<Person> newList1 = personList.stream().filter(person -> person.getName().equals("张三")).collect(Collectors.toList());
        //使用 filter方法过滤出姓名为张三的人加入新的集合
        List<Person> newList2 = personList.stream().distinct().collect(Collectors.toList());
        System.out.println(newList2);
//        DecimalFormat df = new DecimalFormat("#0.000");
//        String format = df.format(3.566f);
//        System.out.println(format);
    }
}
